package com.ruoyi.web.controller.tableSettings;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.system.util.StoreIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TableCategories;
import com.ruoyi.system.service.ITableCategoriesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 桌台分类Controller
 *
 * @author ruoyi
 * @date 2025-05-19
 */
@Api(tags = "桌台分类")
@RestController
@RequestMapping("/system/tableCategories")
public class TableCategoriesController extends BaseController {
    @Autowired
    private ITableCategoriesService tableCategoriesService;
    @Autowired
    private StoreIdUtils storeIdUtils;

    /**
     * 查询桌台分类列表
     */
    @ApiOperation("查询桌台分类列表")
    @PreAuthorize("@ss.hasPermi('system:categories:list')")
    @GetMapping("/list")
    public TableDataInfo list(TableCategories tableCategories) {
        startPage();
//        tableCategories.setStoreId(storeIdUtils.getStoreId());
        List<TableCategories> list = tableCategoriesService.selectTableCategoriesList(tableCategories);
        return getDataTable(list);
    }

    /**
     * 导出桌台分类列表
     */
    @ApiOperation("导出桌台分类列表")
    @PreAuthorize("@ss.hasPermi('system:categories:export')")
    @Log(title = "桌台分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TableCategories tableCategories) {
//        tableCategories.setStoreId(storeIdUtils.getStoreId());
        List<TableCategories> list = tableCategoriesService.selectTableCategoriesList(tableCategories);
        ExcelUtil<TableCategories> util = new ExcelUtil<TableCategories>(TableCategories.class);
        util.exportExcel(response, list, "桌台分类数据");
    }

    /**
     * 通过id获取桌台分类详细信息
     */
    @ApiOperation("通过id获取桌台分类详细信息")
    @PreAuthorize("@ss.hasPermi('system:categories:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tableCategoriesService.selectTableCategoriesById(id));
    }

    /**
     * 新增桌台分类
     */
    @ApiOperation("新增桌台分类")
    @PreAuthorize("@ss.hasPermi('system:categories:add')")
    @Log(title = "桌台分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TableCategories tableCategories) {
//        tableCategories.setStoreId(storeIdUtils.getStoreId());
        return toAjax(tableCategoriesService.insertTableCategories(tableCategories));
    }

    /**
     * 修改桌台分类
     */
    @ApiOperation("修改桌台分类")
    @PreAuthorize("@ss.hasPermi('system:categories:edit')")
    @Log(title = "桌台分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TableCategories tableCategories) {
//        tableCategories.setStoreId(storeIdUtils.getStoreId());
        return toAjax(tableCategoriesService.updateTableCategories(tableCategories));
    }

    /**
     * 通过id批量删除桌台分类信息
     */
    @ApiOperation("通过id批量删除桌台分类信息")
    @PreAuthorize("@ss.hasPermi('system:categories:remove')")
    @Log(title = "桌台分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tableCategoriesService.deleteTableCategoriesByIds(ids));
    }


    @ApiOperation("获取所有桌台的分类信息")
    @GetMapping("/getAllTableCategories")
    public AjaxResult getAllTableCategories() {
        LambdaQueryWrapper<TableCategories> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(TableCategories::getStoreId,storeIdUtils.getStoreId());
        List<TableCategories> list = tableCategoriesService.list(wrapper);
        return success(list);
    }
}
